<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #action="{ record }">
        <TableAction :actions="getActions(record)" />
      </template>
    </BasicTable>
  </div>
  <!--日志详情-->
  <QuartzLogDesc @register="registerDesc" />
</template>
<script lang="ts" name="monitor-quartz-log" setup>
  import { ref } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { getQuartzLogList } from '../quartz.api';
  import { logColumns, searchLogFormSchema } from '../quartz.data';
  import { useRoute } from 'vue-router';
  import { useDrawer } from '/@/components/Drawer';
  import QuartzLogDesc from './QuartzLogDesc.vue';

  const route = useRoute();
  const [registerDesc, { openDrawer: openLogDesc }] = useDrawer();
  // 列表页面公共参数、方法
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    designScope: 'quartz-log-template',
    tableProps: {
      title: '任务日志列表',
      api: getQuartzLogList,
      columns: logColumns,
      actionColumn: {
        width: 80,
      },
      formConfig: {
        labelWidth: 120,
        schemas: searchLogFormSchema,
        fieldMapToTime: [['fieldTime', ['beginDate', 'endDate'], 'YYYY-MM-DD HH:mm:ss']],
      },
      beforeFetch(params) {
        const url = route.fullPath;
        const keyString = '/monitor/quartz/log/';
        let index = url.indexOf(keyString);
        let tmpId = url.substring(index + keyString.length);
        if (tmpId != 'list') {
          params.jobId = tmpId;
        }
      },
    },
  });

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;

  /**
   * 操作列定义
   * @param record
   */
  function getActions(record) {
    return [
      {
        label: '异常详情',
        onClick: handleDetail.bind(null, record),
        ifShow: (_action) => {
          return record.jobResult == '1';
        },
      },
    ];
  }

  function handleDetail(record) {
    openLogDesc(true, {
      record,
      isUpdate: true,
    });
  }
</script>
